package com.allo2o.common.utils;

import org.apache.commons.lang.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by lubingbing on 16-5-11.
 *
 * @auth lubingbing
 */
public class ParseJsonValue {

    /**
     * <ul>
     *     解析json字符串,获取key对应的value
     * </ul>
     * @param jsonStr
     * @param key
     * @return
     */
    public static String getJsonColumnValue(String jsonStr, String key) {
        if (StringUtils.isBlank(jsonStr)) {
            return "";
        } else {
            Pattern pattern = Pattern.compile("\"" + key + "\":\"(.*?)\"");
            Matcher matcher = pattern.matcher(jsonStr);
            if (matcher.find()) {
                return matcher.group(1);
            } else {
                return "";
            }
        }
    }
}
